<template>
  <!-- 检查事项 -->
  <div class="dialog-container">
    <el-dialog
      :title="'处理结果回执单'"
      :visible="dialogVisible"
      @open="initData"
      @close="closeDialog"
    >
      <el-form
        ref="form"
        class="dialog-form"
        :rules="rules"
        label-width="110px"
        size="mini"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="类型" prop="infoType">
              <el-select v-model="processingStatus" class="w-100" placeholder="请输入类型">
                <el-option
                  v-for="(item,index) in processingStatus_s"
                  :key="index+'application_type'"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理结果" prop="processingResults">
              <el-input v-model="processingResults" placeholder="请输入处理结果" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleSave">保存</el-button>
        <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { batch } from '@/api/business/alarm'

export default {
  name: 'HandleDialog',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    batch: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      processingStatus: null,
      processingResults: null,
      processingStatus_s: [
        { value: 'e003_04', label: '处理' },
        { value: 'e003_03', label: '回退' }
      ],
      rules: {
        // examineResult: [{ required: true, message: '请选择违法行为判定', trigger: 'change' }]
      }
    }
  },
  created() {

  },
  methods: {
    initData() {
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    handleSave() {
      this.saveLoading = true
      const dataForm = []
      this.batch.forEach(item => {
        dataForm.push({ id: item.id, processingStatus: this.processingStatus, processingResults: this.processingResults })
      })

      batch(dataForm).then(() => {
        this.$message.success('成功')
        this.$emit('flushPage')
        this.$emit('closeDialog')
        this.clearData()
        this.saveLoading = false
      }).catch(() => {
        this.saveLoading = false
      })
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      this.processingStatus = null
      this.processingResults = null
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
